<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/19 0019
 * Time: 17:57
 */

namespace app\api\controller;


use app\api\library\WechatHandle;
use app\common\controller\Api;
use EasyWeChat\Factory;
use think\Config;
use think\Request;

class Wechat extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $app;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this -> app = Factory::officialAccount(Config::get('wechatConfig'));
    }

    public function index(){

        $this -> app->server->push(WechatHandle::class);

        $response = $this -> app->server->serve();
        $response->send();
        exit;
    }

    public function menu(){
        $buttons = [
               //  [
               //     "type" => "view",
               //     "name" => "注册",
               //     "url"=>"http://rcs.lr8818.com/index/user/register"
               // ],
               // [
               //     "type" => "view",
               //     "name" => "就业意向",
               //     "url"=>"http://rcs.lr8818.com/index/employment/student"
               // ],
               // [
               //     "type" => "view",
               //     "name" => "职业测评",
               //     "url"=>"http://rcs.lr8818.com/index/testing/vocation"
               // ]

//            
//            [
//                "type" => "click",
//                "name" => "生成海报",
//                "key"  => "SCHB"
//            ],
//            [
//                "name"       => "个人中心",
//                "sub_button" => [
//                    [
//                        "type" => "view",
//                        "name" => "申请代理",
//                        "url"=>"http://guojian.baidiyun.com/index/daili/index"
//                    ],
//                    [
//                        "type" => "view",
//                        "name" => "个人中心",
//                        "url"=>"http://guojian.baidiyun.com/index/user/usercenter"
//                    ],
//                    [
//                        "type" => "view",
//                        "name" => "积分商城",
//                        "url"=>"http://guojian.baidiyun.com/addons/leescore/"
//                    ]
//                ]
//            ]
        ];
       // $re = $this -> app->menu->create($buttons);
       // var_dump($re);
       // exit();
    }

    public function getaddress(){
        if($this -> request -> isAjax()){
            $data = $this -> request -> post();
            if(isset($data['lat']) && isset($data['lon']) && $data['lat'] && $data['lon']){
                $address = getAddress($data['lon'],$data['lat']);
                $this -> success('',$address);
            }else{
                $this -> error('参数不完整');
            }
        }else{
            $this -> error('非法请求');
        }
    }
}